#include <iostream>
#include <csignal>
#include <spdlog/spdlog.h>
#include "util/server.hh"
#include "util/util.hh"
#include "controller/user-controller.hh"
#include "controller/word-controller.hh"
#include "controller/vocabulary-controller.hh"
#include "controller/learn-controller.hh"
#include "controller/community-controller.hh"

int main()
{
    WordMemory::SignalUtil::setupHandlers();

    WordMemory::UserController::registerBusiness();
    WordMemory::WordController::registerBusiness();
    WordMemory::VocabularyController::registerBusiness();
    WordMemory::LearnController::registerBusiness();
    WordMemory::CommunityController::registerBusiness();

    try
    {
        WordMemory::Server::instance().run();
    }
    catch (const std::exception &e)
    {
        spdlog::critical("Exception occurred: {}", e.what());
        return 1;
    }
    catch (...)
    {
        spdlog::critical("Unknown error occurred while starting the server.");
        return 1;
    }

    return 0;
}